import org.bukkit.configuration.file.FileConfiguration;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.bukkit.Bukkit.getPluginManager;

public class Order {
    private FileConfiguration config = getPluginManager().getPlugin("RedenTreasure").getConfig();
    private List<String[]> commands = new ArrayList<String[]>() {{
        if (config.getBoolean("test.enable")) {
            add(new String[]{"test"});
        }
        if (config.getBoolean("help.enable")) {
            add(new String[]{"help", "?"});
        }
        if (config.getBoolean("menu.enable")) {
            add(new String[]{"menu", "!"});
        }
        if (config.getBoolean("quest.enable")) {
            add(new String[]{"quest", "q"});
        }
        if (config.getBoolean("workbench.enable")) {
            add(new String[]{"workbench", "wb"});
        }
        if (config.getBoolean("enderchest.enable")) {
            add(new String[]{"enderchest", "ec"});
        }
        if (config.getBoolean("invsee.enable")) {
            add(new String[]{"invsee", "inv"});
        }
        if (config.getBoolean("back.enable")) {
            add(new String[]{"back"});
        }
        if (config.getBoolean("home.enable")) {
            add(new String[]{"home"});
            add(new String[]{"sethome"});
            add(new String[]{"delhome"});
        }
        if (config.getBoolean("spawn.enable")) {
            add(new String[]{"spawn"});
            add(new String[]{"worldspawn"});
        }
        if (config.getBoolean("tpa.enable")) {
            add(new String[]{"tpapply", "tpa"});
            add(new String[]{"tpaccept"});
            add(new String[]{"tpdeny"});
        }
        if (config.getBoolean("suicide.enable")) {
            add(new String[]{"suicide"});
        }
        if (config.getBoolean("position.enable")) {
            add(new String[]{"position"});
        }
        if (config.getBoolean("clock.enable")) {
            add(new String[]{"clock"});
        }
        if (config.getBoolean("nick.enable")) {
            add(new String[]{"nick"});
            add(new String[]{"nickclear"});
            add(new String[]{"prefix"});
            add(new String[]{"prefixclear"});
            add(new String[]{"suffix"});
            add(new String[]{"suffixclear"});
        }
    }};

    public String get(String order) {
        if (order == null || order == "")
            return null;
        for (String[] commands : commands)
            for (String command : Arrays.asList(commands))
                if (order.equalsIgnoreCase(command))
                    return commands[0];
        return null;
    }

    public String[] getAll() {
        String result = "";
        for (String[] command : commands)
            result = result + command[0] + ",";
        return result.split(",");
    }
}
